package com.example.guethe.fireanalysisapp.base;

import com.example.guethe.fireanalysisapp.R;
import com.example.guethe.fireanalysisapp.data.beans.BaseListResponse;
import com.example.guethe.fireanalysisapp.data.beans.BaseResponse;
import com.example.guethe.fireanalysisapp.data.beans.CataLog;
import com.example.guethe.fireanalysisapp.data.beans.CataLogResponse;
import com.example.guethe.fireanalysisapp.data.beans.Device;
import com.example.guethe.fireanalysisapp.data.net.Api;
import com.example.guethe.fireanalysisapp.util.ToastHelper;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;
import cn.droidlover.xrecyclerview.XRecyclerContentLayout;

/**
 * Created by 何建钦 on 2018/3/27.
 */

public class BaseHomePresenter extends XPresent<BaseHomeFragment> {

    protected static final int PAGE_SIZE = 10;

    public void loadData(final int page){
        Api.getBaseService().getLog(page,PAGE_SIZE)
                .compose(XApi.<BaseListResponse<CataLog>>getApiTransformer())
                .compose(XApi.<BaseListResponse<CataLog>>getScheduler())
                .subscribe(new ApiSubscriber<BaseListResponse<CataLog>>() {
                    @Override
                    protected void onFail(NetError error) {
                        getV().showError(error);
                    }

                    @Override
                    public void onNext(BaseListResponse<CataLog> baseResponse) {
                        getV().showData(page, baseResponse);
                    }
                });
    }

    public void loadData(final int page,String type){

        Api.getBaseService().getDevice(page,PAGE_SIZE,type)
                .compose(XApi.<BaseListResponse<Device>>getApiTransformer())
                .compose(XApi.<BaseListResponse<Device>>getScheduler())
                .subscribe(new ApiSubscriber<BaseListResponse<Device>>() {
                    @Override
                    protected void onFail(NetError error) {
                        getV().showError(error);
                    }

                    @Override
                    public void onNext(BaseListResponse<Device> baseResponse) {

                        getV().showData(page, baseResponse,getV().getType());
                    }
                });
    }
}
